package com.example.design.filter.filter;


import com.example.design.DateUtils;
import com.example.design.filter.ScheduleShiftFilter;
import com.example.design.filter.context.ScheduleContext;
import com.example.design.filter.context.ScheduleUser;
import com.example.design.filter.enums.ScheduleShiftEnum;

import java.time.LocalDate;

/**
 * 晚班后不上白班
 */
public class NoDayAfterNightFilter implements ScheduleShiftFilter {

    public static final ScheduleShiftFilter instance = new NoDayAfterNightFilter();

    @Override
    public boolean filter(ScheduleContext context, ScheduleUser user) {
        LocalDate date = context.getScheduleDate();

        // 周一的话,要判断上周日的班次
        if (date.getDayOfWeek().getValue() == 1) {
            return !ScheduleShiftEnum.PRE_SALE_NIGHT.equals(user.getLastSundayShift());
        }
        String yesterdayKey = date.plusDays(-1).format(DateUtils.FORMAT_YYYYMMDD);
        // 昨晚没上晚班
        return !ScheduleShiftEnum.PRE_SALE_NIGHT.equals(user.getShiftMap().get(yesterdayKey));
    }

}
